<?php
/**
 * Uipack
 *
 * JS, CSS 파일을 패키지 형태로 관리하는 클래스
 *
 * @package boot
 * @author  Platform Team
 */

class Uipack
{
    /**
     * 드라이버 객체들 (utilUipackDriver)
     * @var array
     */
    private static $aDriver = array();

    /**
     * Optimmizer 객체
     * @var Optimizer
     */
    private static $Optimizer;

    /**
     * Sslwrap 객체
     * @var Sslwrap
     */
    private static $Sslwrap;

    /**
     * 구동 여부
     * @var boolean
     */
    private static $isProgress;

    /**
     * 드라이버 객체 생성
     * (실패시 false 반환)
     *
     * @param string $sName (드라이버명)
     * @return utilUipackDriver
     */
    public static function driver($sName)
    {
        $sDefaultPrefix = 'utilUipackDriver';

        $sSubcls = _getTypedefDriverName($sName, $sDefaultPrefix);

        if (isset(self::$aDriver[$sSubcls])) {
            return self::$aDriver[$sSubcls];
        }

        $Driver = new $sSubcls(self::$Optimizer, self::$Sslwrap);

        self::$aDriver[$sSubcls] = new utilUipackDriver($Driver);

        return self::$aDriver[$sSubcls];
    }

    /**
     * 초기화(필수)
     *
     * @param Optimizer $Optimizer
     * @param Sslwrap   $Sslwrap
     * @return boolean
     */
    public static function initialize($Optimizer, $Sslwrap)
    {
        if (is_object($Optimizer) === false || is_object($Sslwrap) === false) {
            throw new Exception('Uipack initialize failed', E_ERROR);
        }

        self::$Optimizer = $Optimizer;
        self::$Sslwrap = $Sslwrap;

        return true;
    }
}
